<?php

/**
 * Created by PhpStorm. TempGmAction
 * User: floven
 * Date: 2017/2/13
 * Time: 13:15
 */
class TempGmAction extends SzAbstractAction
{
    Protected $paramTypes = array(
        SzAbstractAction::TYPE_INT,
        SzAbstractAction::TYPE_INT,
        SzAbstractAction::TYPE_INT
    );

    /**
     * @param $userId
     * @param $actionId
     * @param $count
     * @return SzResponse
     */
    public function execute($userId, $actionId, $count)
    {
        if (SzConfig::get()->loadAppConfig('app', 'GM_OPEN')) {
            if ($actionId == '9999999999999') {
                $serversConfigs = SzConfig::get()->loadAppConfig('database', 'MySql');
                $instance = new SzMySqlDb($serversConfigs[0]);
                $platform = $instance->select("SELECT `platformId` FROM `module_sns` where `userId` = {$userId}");

                foreach ($platform as $sns) {
                    $platformId = $sns['platformId'];
                    /* @var ModuleSnsModel $model
                     * @var ModuleSnsVo $vo
                     */
                    $model = SzPersister::get()->getModel(ModuleSnsConst::ORM_NAME_SNS);
                    $vo = $model->retrieve(null, $platformId);
                    $model->deleteVoCache($vo);
                    $model->delete($vo);
                }
            } else if ($actionId == '9999999999998') {
                $redisDb = SzDbFactory::get()->getDb(null, SzAbstractDb::DB_TYPE_REDIS);
                if ($count) {
                   // $redisDb->hSet(GameConst::CACHE_KEY_DIFF_TIME,$userId,($count*3600));
                    $redisDb->hSet(GameConst::CACHE_KEY_DIFF_TIME,$userId,($count));
                } else {
                    //$redisDb->hDel(GameConst::CACHE_KEY_DIFF_TIME,$userId,($count*3600));
                    $redisDb->hDel(GameConst::CACHE_KEY_DIFF_TIME,$userId,($count));
                }
            } else {
                GameService::get()->handleEntity($userId, $actionId, $count, true);
            }
        }

        return $this->buildResponse(array(
            $actionId => $count
        ));
    }
}